﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using SH.STD.Model;
using System.Web.Security;

namespace SH.STD.Web
{
    public partial class SiteMaster : System.Web.UI.MasterPage
    {
        public String UserName
        {
            get
            {
                return Context.User.Identity.Name;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                this.lbUserName.Text = Context.User.Identity.Name;
                var sql = "select FormID from UserRight where UserID='" + Cmn.Session.GetUserID() + "'";
                var dt = Cmn.DB.getDataTable(sql);
                var formIDs = new HashSet<int>();
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    formIDs.Add(int.Parse(dt.Rows[i][0].ToString()));
                }
                this.Project0.Visible = formIDs.Contains(1);
                this.Project1.Visible = formIDs.Contains(2);
                this.Achievement.Visible = formIDs.Contains(3);
                this.Employee.Visible = formIDs.Contains(4);
                this.Committe.Visible = formIDs.Contains(5);
                this.Admin.Visible = formIDs.Contains(6);
                this.Index.Visible = formIDs.Contains(7);
            }
        }

        public void SetTab(TabType tab)
        {
            switch (tab)
            {
                case TabType.Index:
                    {
                        this.tabIndex.Visible = true;
                        this.tabProject0.Visible = false;
                        this.tabProject1.Visible = false;
                        this.tabAchievement.Visible = false;
                        this.tabEmployee.Visible = false;
                        this.tabSearch.Visible = false;
                        this.tabSystem.Visible = false;
                        this.tabBonus.Visible = false;
                        break;
                    }
                case TabType.Project0:
                    {
                        this.tabIndex.Visible = false;
                        this.tabProject0.Visible = true;
                        this.tabProject1.Visible = false;
                        this.tabAchievement.Visible = false;
                        this.tabEmployee.Visible = false;
                        this.tabSearch.Visible = false;
                        this.tabSystem.Visible = false;
                        this.tabBonus.Visible = false;
                        break;
                    }
                case TabType.Project1:
                    {
                        this.tabIndex.Visible = false;
                        this.tabProject0.Visible = false;
                        this.tabProject1.Visible = true;
                        this.tabAchievement.Visible = false;
                        this.tabEmployee.Visible = false;
                        this.tabSearch.Visible = false;
                        this.tabSystem.Visible = false;
                        this.tabBonus.Visible = false;
                        break;
                    }
                case TabType.Employee:
                    {
                        this.tabIndex.Visible = false;
                        this.tabProject0.Visible = false;
                        this.tabProject1.Visible = false;
                        this.tabAchievement.Visible = false;
                        this.tabEmployee.Visible = true;
                        this.tabSearch.Visible = false;
                        this.tabSystem.Visible = false;
                        this.tabBonus.Visible = false;
                        break;
                    }
                case TabType.Achievement:
                    {
                        this.tabIndex.Visible = false;
                        this.tabProject0.Visible = false;
                        this.tabProject1.Visible = false;
                        this.tabAchievement.Visible = true;
                        this.tabEmployee.Visible = false;
                        this.tabSearch.Visible = false;
                        this.tabSystem.Visible = false;
                        this.tabBonus.Visible = false;
                        break;
                    }
                case TabType.Search:
                    {
                        this.tabIndex.Visible = false;
                        this.tabProject0.Visible = false;
                        this.tabProject1.Visible = false;
                        this.tabAchievement.Visible = false;
                        this.tabEmployee.Visible = false;
                        this.tabSearch.Visible = true;
                        this.tabSystem.Visible = false;
                        this.tabBonus.Visible = false;
                        break;
                    }
                case TabType.Committe:
                    {
                        this.tabCommitte.Visible = true;
                        this.tabIndex.Visible = false;
                        this.tabProject0.Visible = false;
                        this.tabProject1.Visible = false;
                        this.tabAchievement.Visible = false;
                        this.tabEmployee.Visible = false;
                        this.tabSearch.Visible = false;
                        this.tabSystem.Visible = false;
                        this.tabBonus.Visible = false;
                        break;
                    }
                case TabType.Admin:
                    {
                        this.tabIndex.Visible = false;
                        this.tabProject0.Visible = false;
                        this.tabProject1.Visible = false;
                        this.tabAchievement.Visible = false;
                        this.tabEmployee.Visible = false;
                        this.tabSearch.Visible = false;
                        this.tabSystem.Visible = true;
                        this.tabBonus.Visible = false;
                        
                        break;
                    }
                case TabType.Bonus:
                    {
                        this.tabIndex.Visible = false;
                        this.tabProject0.Visible = false;
                        this.tabProject1.Visible = false;
                        this.tabAchievement.Visible = false;
                        this.tabEmployee.Visible = false;
                        this.tabSearch.Visible = false;
                        this.tabSystem.Visible = false;
                        this.tabBonus.Visible = true;

                        break;
                    }
                default:
                    break;
            }
        }

        public string Time
        {
            get
            {
                var week = "";
                switch (DateTime.Now.DayOfWeek)
                {
                    case DayOfWeek.Friday:
                        week = "五";
                        break;
                    case DayOfWeek.Monday:
                        week = "一";
                        break;
                    case DayOfWeek.Saturday:
                        week = "六";
                        break;
                    case DayOfWeek.Sunday:
                        week = "日";
                        break;
                    case DayOfWeek.Thursday:
                        week = "四";
                        break;
                    case DayOfWeek.Tuesday:
                        week = "二";
                        break;
                    case DayOfWeek.Wednesday:
                        week = "三";
                        break;
                    default:
                        break;
                }

                return DateTime.Now.Year + "年" + DateTime.Now.Month + "月" + DateTime.Now.Day + "日" + " 星期" + week;
            }
        }

        protected void lbUserName_Click(object sender, EventArgs e)
        {
            Response.Redirect("/Admin/UserManage.aspx?ID="+Cmn.Session.GetUserID());
        }
    }
}
